package gr.handmademarket.ui.panels;

import gr.handmademarket.bl.operations.LoadProductsOperation;
import gr.handmademarket.po.implementations.Product;
import gr.handmademarket.po.implementations.ProductCategory;
import gr.handmademarket.po.interfaces.Category;
import gr.handmademarket.ui.views.ProductsInfoListGrid;

import java.util.List;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

/**
 * thumbnails panel.
 */
public class ProductsInfoPanel 
extends Panel{

	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Creates a new ThumbnailsPanel object. 
	 *
	 * @param id
	 * @param category 
	 */
	@SuppressWarnings("nls")
	public ProductsInfoPanel(String id, Category category, SellerProductsPanel caller) {
		super(id);
		LoadProductsOperation op = new LoadProductsOperation();
		op.setCategory(category);
		op.execute();
		List<Product> products = op.getProducts();
		IDataProvider<Product> dataProvider = new ListDataProvider<Product>(products); 
		boolean isCategory = (category instanceof ProductCategory); 
		ProductsInfoListGrid grid = new ProductsInfoListGrid("rows", dataProvider, isCategory, caller);
		grid.setOutputMarkupId(true);
		grid.setColumns(products.size() < 4 ? products.size() : 4);
		grid.setRows((products.size() / 4) + 1);
		add(grid);
	}

}
